// JavaScript Document
$(document).ready(function() {
	$('textarea.tinymcefull').tinymce({
		// Location of TinyMCE script
		script_url : _baseurl+'data/jscripts/tiny_mce/tiny_mce.js',
		// General options
		language : "vi",
		document_base_url : 'http://tinymce.moxiecode.com',
		relative_urls : true,
		theme : "advanced",
		skin : "o2k7",
		plugins : 'autoresize',
		width: '100%',
		plugins : "noneditable,safari,pagebreak,style,layer,table,advhr,advlink,emotions,iespell,inlinepopups,preview,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
                body_class  :'my-content',
		content_css : _baseurl+"libraries/typography/box.css",
		template_templates:[
                {
                        title       : "Box Editor",
                        src         : _baseurl+"data/jscripts/tiny_mce/templates/box.html",
                        description : "Add box"
                }
            ],
		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,forecolor,backcolor,image,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,undo,redo,|,link,unlink,|,hr,removeformat,cleanup,template",
		theme_advanced_buttons2 : "formatselect,fontselect,fontsizeselect,|,sub,sup,|,charmap,|,fullscreen,|,pastetext,pasteword,|,replace,code",
		//theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "youtube",
		//theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,advhr,|,fullscreen",
		//theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		file_browser_callback: 'openKCFinder',
        setup : function(ed) {
        // Add a custom button
        ed.addButton('youtube', {
            title : 'Chèn video từ youtube, bôi đen link youtube sau đó click vào đây',
            image :  _baseurl+'data/jscripts/tiny_mce/themes/advanced/img/youtube.gif',
            onclick : function() {
                // Add you own code to execute something on click
                ed.focus();
                ed.selection.setContent('[youtube]'+ed.selection.getContent()+'[/youtube]');
            }
        });
        }

	});
	
	$('textarea.tinymcesimple').tinymce({
		// Location of TinyMCE script
		script_url : _baseurl+'data/jscripts/tiny_mce/tiny_mce.js',
		// General options
		language : "vi",
		document_base_url : 'http://tinymce.moxiecode.com',
		relative_urls : true,
		theme : "advanced",
		skin : "o2k7",
		plugins : 'autoresize',
		width: '100%',
		plugins : "paste",
		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,undo,redo,|,cleanup,|,bullist,numlist,|,pastetext,pasteword,|,code",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		file_browser_callback: 'openKCFinder'
	});
});
function openKCFinder(field_name, url, type, win) {
	//alert(url); alert(type); alert(win);
	tinyMCE.activeEditor.windowManager.open({
		file: _baseurl+'data/jscripts/kcfinder/browse.php?opener=tinymce&lang=vi&amp;type=anh',
		title: 'KCFinder',
		width: 700,
		height: 500,
		resizable: "yes",
		inline: true,
		close_previous: "no",
		popup_css: false
	}, {
		window: win,
		input: field_name
	});
	return false;
}